package com.prj.ufdm.webflux.api;

import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/mono")
public class MonoTestApi {
	
	private static final Log log = LogFactory.getLog(MonoTestApi.class);
	
	@RequestMapping(value="/test")
    public Mono<String> test() throws Exception {
		log.info("monotest start");
		Mono<String> result = Mono.fromSupplier( () -> cretateStr());
		log.info("monotest end");
		return result;
    }
	
	@GetMapping("/mvctest")
    public String getMvcTest() throws Exception {
		log.info("mvctest start");
		String result = cretateStr();
		log.info("mvctest end");
		return result;
    }
	
	
	private String cretateStr() {
		try {
			TimeUnit.SECONDS.sleep(5);
		}
		catch(Exception er) {
		}
		return "this is test str";
	}
	
}
